<!doctype html>



  


<html class="theme-next muse use-motion">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  <link href="/vendors/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css"/>




  <link href="//fonts.googleapis.com/css?family=Lato:300,400,700,400italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">



<link href="/vendors/font-awesome/css/font-awesome.min.css?v=4.4.0" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=0.5.0" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="天生DR,DR" />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=0.5.0" />






<meta name="description" content="iOS SDK自身的一些库大多使用Framework的形式提供。Framework的好处都有啥，谁说对了就给他：

将头文件和库文件绑到一起，只要把Framework拖进项目，基本可以做到开箱即用；
可以将多个版本的库文件打包到Framework中，而且可以进行切换。

本文简要介绍了如何手动打包一个Framework的方法。
Framework的文件结构
Framework到底是个啥呢？其实它就">
<meta property="og:type" content="article">
<meta property="og:title" content="iOS项目中静态库Framework的打包">
<meta property="og:url" content="http://www.dr17.me/2015/01/14/ios_framework_package/">
<meta property="og:site_name" content="天生DR">
<meta property="og:description" content="iOS SDK自身的一些库大多使用Framework的形式提供。Framework的好处都有啥，谁说对了就给他：

将头文件和库文件绑到一起，只要把Framework拖进项目，基本可以做到开箱即用；
可以将多个版本的库文件打包到Framework中，而且可以进行切换。

本文简要介绍了如何手动打包一个Framework的方法。
Framework的文件结构
Framework到底是个啥呢？其实它就">
<meta property="og:image" content="/images/20150114-aggregate-target.png">
<meta property="og:image" content="/images/20150114-create-runscript-phase.gif">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="iOS项目中静态库Framework的打包">
<meta name="twitter:description" content="iOS SDK自身的一些库大多使用Framework的形式提供。Framework的好处都有啥，谁说对了就给他：

将头文件和库文件绑到一起，只要把Framework拖进项目，基本可以做到开箱即用；
可以将多个版本的库文件打包到Framework中，而且可以进行切换。

本文简要介绍了如何手动打包一个Framework的方法。
Framework的文件结构
Framework到底是个啥呢？其实它就">




<script type="text/javascript" id="hexo.configuration">
  var NexT = window.NexT || {};
  var CONFIG = {
    scheme: 'Muse',
    sidebar: {"position":"left","display":"post"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: 0,
      author: 'Author'
    }
  };
</script>

  <title> iOS项目中静态库Framework的打包 | 天生DR </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="">

  








  
  
    
  

  <div class="container one-collumn sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta ">
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">天生DR</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle">当上帝亲吻大地的时候于是DR出现了 他是上帝赐予人类最好的礼物</p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu ">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-home fa-fw"></i> <br />
            
            Home
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-archive fa-fw"></i> <br />
            
            Archives
          </a>
        </li>
      

      
      
      
    </ul>
  

  
</nav>

 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                iOS项目中静态库Framework的打包
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            <span class="post-meta-item-icon">
              <i class="fa fa-calendar-o"></i>
            </span>
            <span class="post-meta-item-text">Posted on</span>
            <time itemprop="dateCreated" datetime="2015-01-14T15:59:29+08:00" content="Jan 14 2015">
              Jan 14 2015
            </time>
          </span>

          
            <span class="post-category" >
              &nbsp; | &nbsp;
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">In</span>
              
                <span itemprop="about" itemscope itemtype="https://schema.org/Thing">
                  <a href="/categories/iOS/" itemprop="url" rel="index">
                    <span itemprop="name">iOS</span>
                  </a>
                </span>

                
                

              
            </span>
          

          
            
          

          

          
          
        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      
        <div class="post-gallery" itemscope itemtype="http://schema.org/ImageGallery">
          
          
            <div class="post-gallery-row">
              <a class="post-gallery-img fancybox"
                 href="/images/20150114-aggregate-target.png" rel="gallery_r7gwzyi5um2lwadt"
                 itemscope itemtype="http://schema.org/ImageObject" itemprop="url">
                <img src="/images/20150114-aggregate-target.png" itemprop="contentUrl"/>
              </a>
            
          
            
              <a class="post-gallery-img fancybox"
                 href="/images/20150114-create-runscript-phase.gif" rel="gallery_r7gwzyi5um2lwadt"
                 itemscope itemtype="http://schema.org/ImageObject" itemprop="url">
                <img src="/images/20150114-create-runscript-phase.gif" itemprop="contentUrl"/>
              </a>
            
          

          
          </div>
        </div>
      

      
        <p>iOS SDK自身的一些库大多使用Framework的形式提供。Framework的好处<s>都有啥，谁说对了就给他</s>：</p>
<ul>
<li>将头文件和库文件绑到一起，只要把Framework拖进项目，基本可以做到开箱即用；</li>
<li>可以将多个版本的库文件打包到Framework中，而且可以进行切换。</li>
</ul>
<p>本文简要介绍了如何手动打包一个Framework的方法。</p>
<h2 id="Framework的文件结构">Framework的文件结构</h2>
<p>Framework到底是个啥呢？其实它就是一个目录，里面包含了库文件和头文件，XCode通过这种统一的格式方便对库进行引用。</p>
<p>一个最小的Framework目录的结构如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line"><名称>.framework</名称></div><div class="line">    +-- Headers      # 头文件</div><div class="line">    |    +-- some.h</div><div class="line">    |    +-- another.h</div><div class="line">    +-- <名称>        # 对于静态库项目来说，这是一个.a文件，在framework中则跟framework的名称同名，无扩展名</名称></div></pre></td></tr></table></figure>

<p>其中，Headers目录和Framework同名库均可以做成软链接，以实现多版本共存。一个典型的多版本Framework的目录结构如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div></pre></td><td class="code"><pre><div class="line"><名称>.framework</名称></div><div class="line">    +-- Headers --> 软链接至 Versions/Current/Headers</div><div class="line">    +-- <名称>   --> 软链接至 Versions/Current/<名称></名称></名称></div><div class="line">    +-- Versions</div><div class="line">        +-- Current --> 软链接至 VersionA</div><div class="line">        +-- VersionA</div><div class="line">        |   +-- Headers # 头文件实际位置</div><div class="line">        |   |   +-- some.h</div><div class="line">        |   |   +-- another.h</div><div class="line">        |   +-- <名称>   # 库文件实际位置</名称></div><div class="line">        +-- VersionB</div><div class="line">            +-- Headers</div><div class="line">            |   +-- some.h</div><div class="line">            |   +-- another.h</div><div class="line">            +-- <名称></名称></div></pre></td></tr></table></figure>

<p>所以，实际上我们只需要将静态库项目编译完成后的结果按照相应文件结构复制出来，就完成Framework的打包了 :D</p>
<h2 id="Framework打包实战：libWagon">Framework打包实战：libWagon</h2>
<p>了解了Framework的结构之后，我们可以很轻易地通过写一些shell脚本来自动化Framework的生成，并将其集成到XCode项目中。</p>
<p>首先，为静态库项目创建一个Target，类型选择Aggregate。</p>
<p><img src="/images/20150114-aggregate-target.png" alt="创建Aggregate Target"></p>
<p>这里我们先创建一个适用于真机的Framework包，名称就填写<code>WagonFrameworkIphone</code>。</p>
<p>在这个Target的Build Phases选项中，添加一个Run Script的Phase：</p>
<p><img src="/images/20150114-create-runscript-phase.gif" alt="创建Run Script Phase"></p>
<p>所有想关依赖构建完成后，就会执行这段shell脚本。为了保证方便使用bash扩展，指定使用<code>/bin/bash</code>来执行。</p>
<p>脚本的主要工作就是编译整个静态库项目，然后按照framework的文件结构复制文件。完整的脚本内容如下：</p>
<figure class="highlight shell-script"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div></pre></td><td class="code"><pre><div class="line"><span class="function"><span class="title">build_library</span></span> () {</div><div class="line">    xcrun xcodebuild -project <span class="string">"<span class="variable">${PROJECT_FILE_PATH}</span>"</span> \</div><div class="line">    -target Wagon \</div><div class="line">    -configuration <span class="string">"<span class="variable">${CONFIGURATION}</span>"</span> \</div><div class="line">    -sdk <span class="string">"iphoneos<span class="variable">${1}</span>"</span> \</div><div class="line">    -arch armv7 \</div><div class="line">    -arch armv7s \</div><div class="line">    -arch arm64</div><div class="line">}</div><div class="line"></div><div class="line">SDK_VERSION=`<span class="built_in">echo</span> <span class="variable">$SDK_NAME</span> | sed <span class="operator">-e</span> <span class="string">"s/[A-Za-z]//g"</span>`</div><div class="line"></div><div class="line"><span class="comment">#clean</span></div><div class="line">rm -rf build/Release-iphoneos</div><div class="line">rm -rf build/Wagon.framework</div><div class="line"></div><div class="line"><span class="comment">#build</span></div><div class="line">build_library <span class="string">"<span class="variable">${SDK_VERSION}</span>"</span></div><div class="line"></div><div class="line"><span class="comment">#pack</span></div><div class="line">mkdir -p <span class="string">"build/Wagon.framework"</span></div><div class="line">cp -r <span class="string">"build/Release-iphoneos/include/Wagon"</span> <span class="string">"build/Wagon.framework/Headers"</span></div><div class="line">cp <span class="string">"build/Release-iphoneos/libWagon.a"</span> <span class="string">"build/Wagon.framework/Wagon"</span></div></pre></td></tr></table></figure>

<p>通过<code>xcodebuild</code>生成的项目，生成结果都位于项目同级的<code>build/</code>目录下，直接复制文件即可。</p>
<p>同理，我们也可以为模拟器制作一个target，只需要修改脚本的一小部分：</p>
<figure class="highlight shell-script"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div></pre></td><td class="code"><pre><div class="line"><span class="function"><span class="title">build_library</span></span> () {</div><div class="line">    xcrun xcodebuild -project <span class="string">"<span class="variable">${PROJECT_FILE_PATH}</span>"</span> \</div><div class="line">    -target Wagon \</div><div class="line">    -configuration <span class="string">"<span class="variable">${CONFIGURATION}</span>"</span> \</div><div class="line">    -sdk <span class="string">"iphonesimulator<span class="variable">${1}</span>"</span> \</div><div class="line">    -arch i386 \</div><div class="line">    -arch x86_64</div><div class="line">}</div><div class="line"></div><div class="line">SDK_VERSION=`<span class="built_in">echo</span> <span class="variable">$SDK_NAME</span> | sed <span class="operator">-e</span> <span class="string">"s/[A-Za-z]//g"</span>`</div><div class="line"></div><div class="line"><span class="comment">#clean</span></div><div class="line">rm -rf build/Release-iphonesimulator</div><div class="line">rm -rf build/Wagon.framework</div><div class="line"></div><div class="line"><span class="comment">#build</span></div><div class="line">build_library <span class="string">"<span class="variable">${SDK_VERSION}</span>"</span></div><div class="line"></div><div class="line"><span class="comment">#pack</span></div><div class="line">mkdir -p <span class="string">"build/Wagon.framework"</span></div><div class="line">cp -r <span class="string">"build/Release-iphonesimulator/include/Wagon"</span> <span class="string">"build/Wagon.framework/Headers"</span></div><div class="line">cp <span class="string">"build/Release-iphonesimulator/libWagon.a"</span> <span class="string">"build/Wagon.framework/Wagon"</span></div></pre></td></tr></table></figure>

<h2 id="制作通用版本的库文件">制作通用版本的库文件</h2>
<p><a href="/2015/01/12/iOS_StaticLibrary/">前一篇文章</a>介绍了使用<code>lipo</code>工具将不同平台的二进制文件合成一个统一的fat binary的方法。</p>
<p>借此我们可以将真机使用的库文件和模拟器使用的库文件合并成一个<code>.a</code>文件放进framework中，即可实现一个framework打遍天下XD</p>
<p>再创建一个Aggregate Target，此时将之前建立的两个target拖进依赖列表中，这样在构建通用版本的库文件时，就会先构建前面的两个目标。</p>
<p>为目标添加shell脚本：</p>
<figure class="highlight shell-script"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div></pre></td><td class="code"><pre><div class="line"><span class="title">merge_library</span> () {</div><div class="line">    <span class="title">xcrun</span> lipo -create <span class="string">"<span class="variable">${1}</span>"</span> <span class="string">"<span class="variable">${2}</span>"</span> -output <span class="string">"<span class="variable">${3}</span>"</span></div><div class="line">}</div><div class="line"></div><div class="line">merge_library <span class="string">"build/Release-iphoneos/libWagon.a"</span> <span class="string">"build/Release-iphonesimulator/libWagon.a"</span> <span class="string">"build/libWagon.a"</span></div><div class="line"></div><div class="line"><span class="comment">#pack</span></div><div class="line">mkdir -p <span class="string">"build/Wagon.framework"</span></div><div class="line">cp -r <span class="string">"build/Release-iphoneos/include/Wagon"</span> <span class="string">"build/Wagon.framework/Headers"</span></div><div class="line">cp <span class="string">"build/libWagon.a"</span> <span class="string">"build/Wagon.framework/Wagon"</span></div></pre></td></tr></table></figure>

<p>这样就可以构建出通用的framework了。</p>
<h2 id="framework的使用">framework的使用</h2>
<p>基本上，只需要将framework拖进项目中就可以正常使用了。如果库本身还需要依赖一些外部组件，则需要在项目中引用那些外部的动态库或者framework；此外，为了支持ObjC的categories，还需要在链接选项中添加<code>-ObjC</code>。</p>

      
    </div>

    <footer class="post-footer">
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2015/01/13/iOS_StaticLibrary/" rel="next" title="iOS静态库">
                <i class="fa fa-chevron-left"></i> iOS静态库
              </a>
            
          </div>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2015/01/21/network_link_conditinder/" rel="prev" title="Network Link Conditioner">
                Network Link Conditioner <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            Table of Contents
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            Overview
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel ">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="http://7u2ibm.com1.z0.glb.clouddn.com/avatar.png"
               alt="窦静轩" />
          <p class="site-author-name" itemprop="name">窦静轩</p>
          <p class="site-description motion-element" itemprop="description">我跑啊跑啊跑 为的就是赶上那个被寄予厚望的自己</p>
        </div>
        <nav class="site-state motion-element">
          <div class="site-state-item site-state-posts">
            <a href="/archives">
              <span class="site-state-item-count">15</span>
              <span class="site-state-item-name">posts</span>
            </a>
          </div>
          
          
            <div class="site-state-item site-state-categories">
              
                <span class="site-state-item-count">12</span>
                <span class="site-state-item-name">categories</span>
              
            </div>
          

          
            <div class="site-state-item site-state-tags">
              
                <span class="site-state-item-count">1</span>
                <span class="site-state-item-name">tags</span>
              
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
        </div>

        
        

        <div class="links-of-author motion-element">
          
        </div>

      </section>

      
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc-indicator-top post-toc-indicator">
            <i class="fa fa-angle-double-up"></i>
          </div>
          <div class="post-toc">
            
              
            
            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#Framework的文件结构"><span class="nav-number">1.</span> <span class="nav-text">Framework的文件结构</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Framework打包实战：libWagon"><span class="nav-number">2.</span> <span class="nav-text">Framework打包实战：libWagon</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#制作通用版本的库文件"><span class="nav-number">3.</span> <span class="nav-text">制作通用版本的库文件</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#framework的使用"><span class="nav-number">4.</span> <span class="nav-text">framework的使用</span></a></li></ol></div>
            
          </div>
          <div class="post-toc-indicator-bottom post-toc-indicator">
            <i class="fa fa-angle-double-down"></i>
          </div>
        </section>
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2016</span>
  <span class="with-love">
    <i class="icon-next-heart fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">窦静轩</span>
</div>

<div class="powered-by">
  Powered by <a class="theme-link" href="http://hexo.io">Hexo</a>
</div>

<div class="theme-info">
  Theme -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Muse
  </a>
</div>



      </div>
    </footer>

    <div class="back-to-top"></div>
  </div>

  


  



  <script type="text/javascript" src="/vendors/jquery/index.js?v=2.1.3"></script>

  <script type="text/javascript" src="/vendors/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  <script type="text/javascript" src="/vendors/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  <script type="text/javascript" src="/vendors/velocity/velocity.min.js"></script>

  <script type="text/javascript" src="/vendors/velocity/velocity.ui.min.js"></script>

  <script type="text/javascript" src="/vendors/fancybox/source/jquery.fancybox.pack.js"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=0.5.0"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=0.5.0"></script>



  
  

  
  
<script type="text/javascript" src="/js/src/scrollspy.js?v=0.5.0"></script>

<script type="text/javascript" id="sidebar.toc.highlight">
  $(document).ready(function () {
    var tocSelector = '.post-toc';
    var $tocSelector = $(tocSelector);
    var activeCurrentSelector = '.active-current';

    $tocSelector
      .on('activate.bs.scrollspy', function () {
        var $currentActiveElement = $(tocSelector + ' .active').last();

        removeCurrentActiveClass();
        $currentActiveElement.addClass('active-current');

        $tocSelector[0].scrollTop = $currentActiveElement.position().top;
      })
      .on('clear.bs.scrollspy', function () {
        removeCurrentActiveClass();
      });

    function removeCurrentActiveClass () {
      $(tocSelector + ' ' + activeCurrentSelector)
        .removeClass(activeCurrentSelector.substring(1));
    }

    function processTOC () {
      getTOCMaxHeight();
      toggleTOCOverflowIndicators();
    }

    function getTOCMaxHeight () {
      var height = $('.sidebar').height() -
                   $tocSelector.position().top -
                   $('.post-toc-indicator-bottom').height();

      $tocSelector.css('height', height);

      return height;
    }

    function toggleTOCOverflowIndicators () {
      tocOverflowIndicator(
        '.post-toc-indicator-top',
        $tocSelector.scrollTop() > 0 ? 'show' : 'hide'
      );

      tocOverflowIndicator(
        '.post-toc-indicator-bottom',
        $tocSelector.scrollTop() >= $tocSelector.find('ol').height() - $tocSelector.height() ? 'hide' : 'show'
      )
    }

    $(document).on('sidebar.motion.complete', function () {
      processTOC();
    });

    $('body').scrollspy({ target: tocSelector });
    $(window).on('resize', function () {
      if ( $('.sidebar').hasClass('sidebar-active') ) {
        processTOC();
      }
    });

    onScroll($tocSelector);

    function onScroll (element) {
      element.on('mousewheel DOMMouseScroll', function (event) {
          var oe = event.originalEvent;
          var delta = oe.wheelDelta || -oe.detail;

          this.scrollTop += ( delta < 0 ? 1 : -1 ) * 30;
          event.preventDefault();

          toggleTOCOverflowIndicators();
      });
    }

    function tocOverflowIndicator (indicator, action) {
      var $indicator = $(indicator);
      var opacity = action === 'show' ? 1 : 0;
      $indicator.velocity ?
        $indicator.velocity('stop').velocity({
          opacity: opacity
        }, { duration: 100 }) :
        $indicator.stop().animate({
          opacity: opacity
        }, 100);
    }

  });
</script>

<script type="text/javascript" id="sidebar.nav">
  $(document).ready(function () {
    var html = $('html');
    var TAB_ANIMATE_DURATION = 200;
    var hasVelocity = $.isFunction(html.velocity);

    $('.sidebar-nav li').on('click', function () {
      var item = $(this);
      var activeTabClassName = 'sidebar-nav-active';
      var activePanelClassName = 'sidebar-panel-active';
      if (item.hasClass(activeTabClassName)) {
        return;
      }

      var currentTarget = $('.' + activePanelClassName);
      var target = $('.' + item.data('target'));

      hasVelocity ?
        currentTarget.velocity('transition.slideUpOut', TAB_ANIMATE_DURATION, function () {
          target
            .velocity('stop')
            .velocity('transition.slideDownIn', TAB_ANIMATE_DURATION)
            .addClass(activePanelClassName);
        }) :
        currentTarget.animate({ opacity: 0 }, TAB_ANIMATE_DURATION, function () {
          currentTarget.hide();
          target
            .stop()
            .css({'opacity': 0, 'display': 'block'})
            .animate({ opacity: 1 }, TAB_ANIMATE_DURATION, function () {
              currentTarget.removeClass(activePanelClassName);
              target.addClass(activePanelClassName);
            });
        });

      item.siblings().removeClass(activeTabClassName);
      item.addClass(activeTabClassName);
    });

    $('.post-toc a').on('click', function (e) {
      e.preventDefault();
      var targetSelector = NexT.utils.escapeSelector(this.getAttribute('href'));
      var offset = $(targetSelector).offset().top;
      hasVelocity ?
        html.velocity('stop').velocity('scroll', {
          offset: offset  + 'px',
          mobileHA: false
        }) :
        $('html, body').stop().animate({
          scrollTop: offset
        }, 500);
    });

    // Expand sidebar on post detail page by default, when post has a toc.
    NexT.motion.middleWares.sidebar = function () {
      var $tocContent = $('.post-toc-content');

      if (CONFIG.sidebar === 'post') {
        if ($tocContent.length > 0 && $tocContent.html().trim().length > 0) {
          NexT.utils.displaySidebar();
        }
      }
    };
  });
</script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=0.5.0"></script>



  



  



  
  

  
  


</body>
</html>
